package ma.projet.managedbean;

import java.io.Serializable;
import java.util.List;


import javax.faces.bean.ManagedProperty;



import ma.projet.beans.Specialite;

import ma.projet.service.SpecialiteService;

import org.hibernate.HibernateException;

public class SpecialiteBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Specialite specialite;
	private List<Specialite> specialites;
	private SpecialiteService specialiteservice;
	@ManagedProperty("#{param.specialiteid}")
	private String specialiteid;

	public SpecialiteBean() {
		specialite = new Specialite();
		specialiteservice = new SpecialiteService();

	}

	public Specialite getSpecialite() {
		return specialite;
	}

	public void setSpecialite(Specialite specialite) {
		this.specialite = specialite;
	}

	public List<Specialite> getSpecialites() throws HibernateException {
		if (specialites == null)
			try {
				specialites = specialiteservice.load();
			} catch (HibernateException e) {
				System.out.println("Erreur Liste");
			}
		return specialites;
	}

	public void setSpecialites(List<Specialite> specialites) {
		this.specialites = specialites;
	}

	public SpecialiteService getSpecialiteservice() {
		return specialiteservice;
	}

	public void setSpecialiteservice(SpecialiteService specialiteservice) {
		this.specialiteservice = specialiteservice;
	}

	public String getSpecialiteid() {
		return specialiteid;
	}

	public void setSpecialiteid(String specialiteid) {

		this.specialiteid = specialiteid;
		try {
			if (specialiteid != null && !specialiteid.equals("")) {
				int id = Integer.parseInt(specialiteid);
				if (specialiteservice != null) {
					this.specialite = specialiteservice.getById(id);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

//	public String createPatient() {
//		patientservice.create(patient);
//		return "listeProfil";
//	}
//
//	public String deletePatient() {
//		patientservice.delete(patient);
//		return "listeProfil";
//	}
//
//	public String updatePatient() {
//		patientservice.update(patient);
//		return "listeProfil";
//	}
//
//	public void savePatient(ActionEvent actionEvent) {
//		FacesContext.getCurrentInstance().addMessage(
//				null,
//				new FacesMessage("Welcome " + patient.getNom() + " "
//						+ patient.getPrenom() + "!"));
//	}
//
//

	
	public List<Specialite> listsp()
	{
		SpecialiteService sp=new SpecialiteService();
		return sp.load();
		
	}

}
